/**
 * 
 */
package feedbox;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author eddieverasousa
 * Criptografia no banco!
 *
 **/
public class Util {
	private static final String hexDigits = "0123456789abcdef";

	static public String generateCrypt(String passwd) {
		
		MessageDigest algorithm;
		try {
			algorithm = MessageDigest.getInstance("SHA-256");
			algorithm.reset();
			byte[] b = algorithm.digest(passwd.getBytes());
			StringBuffer encrypted = new StringBuffer();
			for (int i = 0; i < b.length; i++) {
				int j = ((int) b[i]) & 0xFF;
				encrypted.append(hexDigits.charAt((int) j / 16));
				encrypted.append(hexDigits.charAt((int) j % 16));
			}
		
			return encrypted.toString();
		
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
	}

	
	
}
